package com.cn.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName SqlsesstionUtil
 * @Description TODO
 * @Author yujiajing
 * @Date 2022/9/30 21:52
 * @Version 1.0
 */
public class SqlsesstionUtil {
    public static SqlSession getSqlSession(){
        try {
            InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
            SqlSession sqlSession = sqlSessionFactoryBuilder.build(is).openSession(true);
            return sqlSession;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
